package ru.housewife.model;

import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.List;

import static org.hibernate.annotations.CascadeType.ALL;
import static org.hibernate.annotations.CascadeType.DELETE_ORPHAN;

/**
 * Entity for ingredients
 * Each ingredient could belong to some recipe.
 * Each ingredient have list of possible wares and default ware
 *
 * @author atroshanin
 */
@Entity
@Table(name = "INGREDIENTS")
@SequenceGenerator(name = "ingredients", sequenceName = "INGREDIENTS_SEQ")
public class Ingredient {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ingredients")
    @Column(name = "ID")
    private Long id;

    @Column(name = "NAME", length = 50)
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "GROUP_ID")
    private IngredientGroup ingredientGroup;

/*
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "DEFAULT_WARE_ID")
    private Ware defaultWare;
*/

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "ingredient", cascade = CascadeType.ALL)
    @Cascade({ ALL, DELETE_ORPHAN })
    private List<Ware> wares;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public IngredientGroup getIngredientGroup() {
        return ingredientGroup;
    }

    public void setIngredientGroup(IngredientGroup ingredientGroup) {
        this.ingredientGroup = ingredientGroup;
    }

    public List<Ware> getWares() {
        return wares;
    }

    public void setWares(List<Ware> wares) {
        this.wares = wares;
    }
}
